package com.example.javademo;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SimpleActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple);  // 加载主布局

        // 1. 准备数据
        List<Map<String, Object>> data = new ArrayList<>();

        Map<String, Object> item1 = new HashMap<>();
        item1.put("title", "Item 1");
        item1.put("description", "This is item one");
        item1.put("icon", R.drawable.today); // 使用系统图标示例

        Map<String, Object> item2 = new HashMap<>();
        item2.put("title", "Item 2");
        item2.put("description", "This is item two");
        item2.put("icon", R.mipmap.ic_launcher_round);

        data.add(item1);
        data.add(item2);

        // 2. 定义映射关系
        String[] from = {"title", "description", "icon"};
        int[] to = {R.id.textViewTitle, R.id.textViewDescription, R.id.imageViewIcon};

        // 3. 创建SimpleAdapter
        SimpleAdapter adapter = new SimpleAdapter(
                this,
                data,
                R.layout.list_item,  // 列表项布局
                from,
                to
        );

        // 4. 获取ListView并设置适配器
        ListView listView = findViewById(R.id.myListView); // 从主布局获取ListView
        listView.setAdapter(adapter);
    }
}